<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('admin_tokens')) return;
        Schema::create('admin_tokens', function (Blueprint $table) {
            $table->id()->unsigned()->autoIncrement();
            $table->unsignedBigInteger('admin_id')->default(0)->index()->comment('管理员ID，关联admins表ID');
            $table->string('token', 50)->default('')->comment('登录token');
            $table->unsignedBigInteger('expire_time')->default(0)->comment('token到期时间戳');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
        DB::statement("ALTER TABLE `admin_tokens` COMMENT 'admin_tokens'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('admin_tokens');
    }
};
